package com.coscon.controller;

import com.coscon.controller.base.BaseController;
import com.coscon.model.ProcessInformations;
import com.coscon.model.ResponseResult;
import com.coscon.model.api.ResponseCode;
import com.coscon.service.ProcessService;
import com.coscon.utils.WakeOnLan;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;


/**
 * 进程列表
 */
@Controller
@RequestMapping("/jm/manager/process")
@Slf4j
public class ProcessListController extends BaseController {

    @Resource
    private ProcessService processService;

    /**
     * 进入进程列表首页
     * @param request
     * @return
     * @throws IOException
     */
    @GetMapping("/index")
    public ModelAndView welcomePage(HttpServletRequest request) throws IOException {
        ModelAndView v = new ModelAndView("appPage/processList");
        List<ProcessInformations> list = this.processService.getProcessInformations();
        v.addObject("processList",list);
        return v;
    }


    @PostMapping("/killByPid")
    public @ResponseBody
    ResponseResult<Boolean> killByPid(
            HttpServletRequest request
            ,  @RequestParam(value = "pid", required = false) String pid
    ){
        boolean f = this.processService.killByPid(pid);
        return new ResponseResult(ResponseCode.OK.getCode(),ResponseCode.OK.getMsg(),f);
    }
    

}
